﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;
using Antu.Core.DataAccess;

namespace WebSys.UI.Control.ZhengShou
{
    public class ZS_AddPCHRYControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            
            if (!base.Page.IsPostBack)
            {
                BindData();
            }
            CustomGridView CustomGridView1 = (CustomGridView)FindControl("CustomGridView1");
            CustomGridView1.OnLoadData += new EventHandler(CustomGridView1_OnLoadData);
            CustomGridView1.RowDeleting += new GridViewDeleteEventHandler(CustomGridView1_RowDeleting);
            Button btnSeach = (Button)FindControl("btnSeach");
            btnSeach.Click += new EventHandler(btnSeach_Click);

            if (!string.IsNullOrEmpty(base.Page.Request["action"]) && base.Page.Request["action"] == "view")
            {
                base.Page.ClientScript.RegisterStartupScript(this.GetType(), "aa", "<script>duspaly();</script>");
                CustomGridView1.Columns[12].Visible = false;
                CustomGridView1.Columns[13].Visible = false;
            }
        }
        protected void btnSeach_Click(object sender, EventArgs e)
        {
            BindData();
        }
        protected void BindData()
        {
            CustomGridView CustomGridView1 = (CustomGridView)FindControl("CustomGridView1");
            CustomGridView1.RowDataBound+=new GridViewRowEventHandler(CustomGridView1_RowDataBound);
            string strPCID = base.Page.Request["PCID"];
            if (!string.IsNullOrEmpty(strPCID))
            {
                DataTable dt = _EluZSDataProvider.GetHZJERY(strPCID, GetStrWhere());
                CustomGridView1.DataSource = dt;
                CustomGridView1.RecordCount = dt.Rows.Count;
                CustomGridView1.HideColName = "id";
                CustomGridView1.DataKeyNames = new string[] { "id" };
                CustomGridView1.DataBind();
            }
            Label Label2 = (Label)FindControl("Label2");
            Label2.Text = _EluZSDataProvider.GetSomeStr("ZS_ZSPCH", "征收批次号", "pcid", strPCID);
        }
        protected void CustomGridView1_OnLoadData(object sender, EventArgs e)
        {
            BindData();
        }
        protected void CustomGridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView dr = (DataRowView)e.Row.DataItem;
                string strID = dr["ID"].ToString();
                string temp1 = e.Row.Cells[6].Text;//评估补偿额
                string temp2 = e.Row.Cells[7].Text;//产品补偿额
                string temp3 = e.Row.Cells[8].Text;//货币化补偿额
                string temp4 = e.Row.Cells[9].Text;//已划转金额
                double tt = 0.00;
                double tt1 = 0; double tt2 = 0; double tt3 = 0; double tt4 = 0; double tt5 = 0;
                if (string.IsNullOrEmpty(temp1) || temp1 == "&nbsp;") { temp1 = "0"; }
                if (string.IsNullOrEmpty(temp2) || temp2 == "&nbsp;") { temp2 = "0"; }
                if (string.IsNullOrEmpty(temp3) || temp3 == "&nbsp;") { temp3 = "0"; }
                if (string.IsNullOrEmpty(temp4) || temp4 == "&nbsp;") { temp4 = "0"; }
                tt1 = Convert.ToDouble(temp1); tt2 = Convert.ToDouble(temp2); tt3 = Convert.ToDouble(temp3); tt4 = Convert.ToDouble(temp4);
                //tt = (tt1 + tt2 + tt3) - tt4;
                tt = (tt2 + tt3) - tt4;
                e.Row.Cells[11].Text = tt.ToString();//获取的余额
                string strTJZT = dr["提交状态"].ToString();
                if (strTJZT == "1")
                {
                    e.Row.Cells[13].Enabled = false;
                    e.Row.Cells[13].Text = "删除";
                }
            }
        }
        protected void CustomGridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            CustomGridView CustomGridView1 = (CustomGridView)FindControl("CustomGridView1");
            string strid = CustomGridView1.DataKeys[e.RowIndex].Value.ToString();
            bool del = _EluZSDataProvider.DeleteXmByID("ZS_ZSPCH", "id", strid);
            if (del) {
                BindData();
                base.Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('删除成功！')", true);
            }
        }
        
        protected string GetStrWhere() {
            TextBox TextBox1 = (TextBox)FindControl("TextBox1");
            string strWhere = string.Empty;
            if (!string.IsNullOrEmpty(TextBox1.Text))
            {
                strWhere += " and 产权人 like '%" + TextBox1.Text.Trim() + "%'";
            }
            return strWhere;
        }
    }
}


